import org.molamil.acto.mc.mcw.LcMcWrapper;

/**
 * Associates the mouse events from a <code>MovieClip</code> to a <code>LcMcWrapper</code>:
 * <ul>
 * 	<li><code>onRollOver</code>: sets <code>state</code> to <cite>"IN"</cite>.</li>
 * 	<li><code>onRollOut</code>: sets <code>state</code> to <cite>"OUT"</cite>.</li>
 * </ul>
 *
 * @author Jorge Hernandez
 */
class org.molamil.acto.mc.MouseStateMcw {
	
	
	//FIXME: Test.
	//TODO: Review.
	//TODO: onPress?
	

	// Constructor
	
	private function MouseStateMcw() {}
	
	
	// Functions
	
	//XXX: Document.
	public static function link(origin_mc:MovieClip, target_mc:Object, mcw:Function):LcMcWrapper {
		
		// If no target_mc is passed, set the origin_mc as the target.
		if (target_mc == null)
			target_mc = origin_mc;
		
		var lcmcw:LcMcWrapper;
		
		// Check whether mouseEvents_mc is already a LcMcWrapper.
		if (target_mc instanceof LcMcWrapper) {
			lcmcw = LcMcWrapper(target_mc);
		} else {
			lcmcw = new mcw();
			lcmcw.mc = MovieClip(target_mc);
		}
		
		// Add the mouse events.
		origin_mc.onRollOver = function():Void {
			lcmcw.state = LcMcWrapper.STATE_IN;
		};
		origin_mc.onRollOut = function():Void {
			lcmcw.state = LcMcWrapper.STATE_OUT;
		};
		
		return lcmcw;
		
	}
	
	
}